package com.ljxt.dt.dao.storemanagementdao.impl;

import com.ljxt.dt.dao.storemanagementdao.DetailDao;
import com.ljxt.dt.domain.HandlerInfo;
import com.ljxt.dt.domain.ReceptDetail;
import com.ljxt.dt.domain.ReceptInfo;
import com.ljxt.dt.util.DaoUtil;
import com.ljxt.dt.vo.storemanagement.ReceptDetailVO;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 唐春劲
 * @version 1.0.0
 * @date 2020-05-11 21:46
 * @copyright 老九学堂
 */

public class DetailDaoImpl implements DetailDao {
    @Override
    public ReceptInfo selectOnly(String id) {
        String sql = "select * from recept_info where recept_no = ?";
        return DaoUtil.querySelectOnly(sql,new ReceptInfo(),id);
    }

    @Override
    public List<ReceptDetail> selectDetailGoods(String id) {
        String sql = "select * from recept_detail where recept_no = ?";


        return  DaoUtil.querySelectAll(sql,new ReceptDetail(),id);
    }

    @Override
    public List<String> selectDetailAttrs(Object... params) {
        String sql = "select attr_name from attr_info where id in (";
        //循环添加sql
        List<Object> newParams = new ArrayList<>();
        if(params.length == 0){

        }else {
            for (Object o : params){
                if(o.toString().trim().isEmpty()){
                    newParams.add(o.toString());
                    continue;
                }
                String str = o.toString().split("-")[1];
                newParams.add(str);
            }
        }

        for (int i = 0; i < params.length; i++) {
            sql +=" ?,";
        }

        sql = sql.substring(0,sql.lastIndexOf(','));
        sql+=")";


        return DaoUtil.querySelectStringAll(sql,newParams.toArray());
    }

    @Override
    public String selectShelevs(int id) {

        //根据ID查找货架以及仓库的名称
        String sql = "select name  from shelves where id = ?";
        String sql2 = "select name from warehouse where id = (SELECT warehouse_id FROM shelves where id = ?)";
        String name1 = DaoUtil.querySelectString(sql,id);
        String name2 = DaoUtil.querySelectString(sql2,id);


        return name2+":"+name1;
    }

    @Override
    public String selectGys(Integer supplierId) {
        String sql = "select supplier_name from supplier_info  where id  = (  select supplier_id from supplier_goods where goods_id = ?)";

        return DaoUtil.querySelectString(sql,supplierId);
    }

    @Override
    public List<HandlerInfo> selectInfo(String id) {
        String sql = "select * from handler_info where order_no = ?";
        return DaoUtil.querySelectAll(sql,new HandlerInfo() ,id);
    }
}
